package com.ccy.legendary.socker;

import com.ccy.legendary.base.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/message")
public class WSMessageController extends BaseController {
    private final WSMessageService wsMessageService;

    public WSMessageController(WSMessageService wsMessageService) {
        this.wsMessageService = wsMessageService;
    }

    //请求入口
    @RequestMapping(value="/ws_request",method= RequestMethod.GET)
    @ResponseBody
    public String TestWS(@RequestParam(value="soursUserCode")String soursUserCode,
                         @RequestParam(value="targetUserCode")String targetUserCode,
                         @RequestParam(value="message") String message) throws Exception{
        logger.debug("收到发送请求，{}向用户{}的消息：{}",soursUserCode,targetUserCode,message);
        if(wsMessageService.sendTheUser(targetUserCode, message)){
            return "发送成功";
        }else{
            return "发送失败";
        }
    }
}
